-- Function: "SoaySNPchip".fun_writefasta(text)

-- DROP FUNCTION fun_readfasta();

CREATE OR REPLACE FUNCTION fun_readfasta() RETURNS void AS $$

  import psycopg2
  import os
  import re

  try:
      conn = psycopg2.connect("dbname='Soay' user='dberaldi' host='localhost' password='mypassword'");
  except:
      return("I am unable to connect to the database")

  cur = conn.cursor()

  cur.execute('DROP TABLE IF EXISTS tmp_readfasta')

  cur.execute("""CREATE TABLE tmp_readfasta (
    fasta_name text,
    fasta_seq text
    )
    """)
                       
  fastain= open(fasta_file)
  for line in fastain:
  while 1<2:
      line= fastain.readline()
      if line.startswith('>'):
          fasta_name= line
          continue
      else:
          line= fastain.readline()
                
          line.split('\t')
      
      cur = conn.cursor() 
      newr = 'INSERT INTO tmp_readfasta SELECT ' + line[]
      cur.execute('bla', 'bla2' """)

##  fastaout= cur.fetchall()

##  fastaout= list(fastaout)
##  return(fastaout);

##   END;
$$ LANGUAGE plpythonu;





